package com.hunau.novel_reading.controller;

import com.hunau.novel_reading.common.R;
import com.hunau.novel_reading.request.FavoritesInsertReq;
import com.hunau.novel_reading.request.FavoritesSeekReq;
import com.hunau.novel_reading.service.FavoritesService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/favorites")
public class FavoritesController {
    @Resource
    private FavoritesService favoritesService;
    @RequestMapping("/insert")
    public R insert(@RequestBody @Valid FavoritesInsertReq favoritesInsertReq){
        if (favoritesService.insertFavoritesRecordByUserAndBookName(favoritesInsertReq) == 1)
            return R.ok().message("插入成功");
        else
            return R.error().message("插入失败");
    }
    @RequestMapping("/seek")
    public R seek(@RequestBody @Valid FavoritesSeekReq favoritesSeekReq){
        return R.ok().data("books",favoritesService.selectBooksByUsername(favoritesSeekReq));
    }
}
